package io.knifer.gokexceltask.excel.converter;

import com.alibaba.excel.converters.Converter;
import com.alibaba.excel.enums.CellDataTypeEnum;
import com.alibaba.excel.metadata.GlobalConfiguration;
import com.alibaba.excel.metadata.data.ReadCellData;
import com.alibaba.excel.metadata.data.WriteCellData;
import com.alibaba.excel.metadata.property.ExcelContentProperty;
import io.knifer.gokexceltask.pojo.domain.Major;
import io.knifer.gokexceltask.utils.CellDataUtils;

public class MajorConverter implements Converter<Major> {
    @Override
    public Class<?> supportJavaTypeKey() {
        return Major.class;
    }

    @Override
    public CellDataTypeEnum supportExcelTypeKey() {
        return CellDataTypeEnum.STRING;
    }

    @Override
    public Major convertToJavaData(ReadCellData<?> cellData, ExcelContentProperty contentProperty, GlobalConfiguration globalConfiguration) throws Exception {
        return new Major(null, CellDataUtils.get(cellData), null, null, null);
    }

    @Override
    public WriteCellData<String> convertToExcelData(Major value, ExcelContentProperty contentProperty, GlobalConfiguration globalConfiguration) throws Exception {
        return new WriteCellData<>(value.getName());
    }
}
